/*
Copyright (C) 2012 John Tsiombikas <nuclear@member.fsf.org>,
                   Ioannis Makris <imak@imak.gr>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef GLORY_PRIV_H_
#define GLORY_PRIV_H_

#include "glory.h"

/* opaque structure to be defined and used by each window system module */
struct wsys_window;

/* callback stack node */
struct cbnode {
	void (*func[GLORY_NUM_CALLBACKS])();
	void *cls[GLORY_NUM_CALLBACKS];
	/* bitmask of enabled callbacks (1 << cbidx) */
	unsigned int cbmask;

	struct cbnode *next;
};

struct window {
	int id;
	struct wsys_window *wsys_win;

	struct cbnode *cb;
	struct cbnode first_cbnode;

	int mouse_index;

	struct window *next;
};


#define ATTR_SCREEN_VALID	0x80000000

struct gloin_attr {
	int rbits, gbits, bbits;
	int zbits, sbits;
	int msamples;
	int stereo, doublebuf;
	int api;
	int scrnum;

	unsigned int valid; /* valid mask */
} gloin_attr;

/* internal window-related functions act on a particular window
 * All internal functions start with the gloin prefix and are not
 * meant to be called by users.
 */
struct window *gloin_create_window(int xsz, int ysz, unsigned int mode);
void gloin_destroy_window(struct window *win);

void gloin_set_active(struct window *win);
struct window *gloin_get_active(void);

int gloin_mouse_id(struct window *win);

void gloin_push_callbacks(struct window *win);
void gloin_pop_callbacks(struct window *win);
void gloin_clear_callbacks(struct window *win);
void gloin_set_callback(struct window *win, int cb, void (*func)(), void *cls);
void (*gloin_get_callback(struct window *win, int cb))();
void *gloin_get_callback_data(struct window *win, int cb);

struct window *gloin_winlist(void);

/* helper function to determine if the event loop should block or not */
int gloin_have_idle(void);

/* helper function to call create/reshape callbacks on newly created windows */
void gloin_call_create(struct window *win);

/* helper function to call all registered idle callbacks */
void gloin_call_idle(void);

#endif	/* GLORY_PRIV_H_ */
